package com.yzs.core.base

import android.view.LayoutInflater
import androidx.lifecycle.LiveData
import androidx.viewbinding.ViewBinding
import com.yzs.base.base.BaseVBActivity
import com.yzs.core.bean.NetworkViewState
import com.yzs.core.bean.PageStatus

/**
 *    author : yzs
 *    date   : 2022/1/1316:04
 *    desc   : 业务层 便捷使用 viewBinding
 */
abstract class CoreBaseVBActivity<VB : ViewBinding>(
    inflate: (LayoutInflater) -> VB
) : BaseVBActivity<VB>(inflate) {

    /**
     * 在基类统一处理加载框
     * 如果不需要统一处理，可以重写该方法 不调用 super
     */
    open fun setPageStateLoadingUI(viewStates: LiveData<NetworkViewState>) {
        viewStates.observeKtNoNull {
            when (it.pageStatus) {
                is PageStatus.LOADING -> showLoadingDialog()
                is PageStatus.SUCCESS -> dismissLoadingDialog()
                is PageStatus.FAILURE -> dismissLoadingDialog()
            }
        }
    }
}